<?php
class Zend_View_Helper_LoggedInAs extends Zend_View_Helper_Abstract{

	public function loggedInAs (){

		$auth = Zend_Auth::getInstance();

		if ($auth->hasIdentity()) {

			
			$username = $auth->getIdentity()->first_name;
			$logoutUrl = $this->view->url(array('controller'=>'admin',

					'action'=>'logout'), null, true);
			
			return 'Welcome ' . $username .  '. <a href="'.$logoutUrl.'">Logout</a>';
		}

		$request = Zend_Controller_Front::getInstance()->getRequest();
		$controller = $request->getControllerName();
		$action = $request->getActionName();

		if($controller == 'admin' && $action == 'index') {
			return '';
		}

		$loginUrl = $this->view->url(array('controller'=>'admin', 'action'=>'login'));
		return '<a href="'.$loginUrl.'">Login</a>';
	}
}